import 'isomorphic-fetch';
import api from  '../api';

export default ctx => {
	let headers = {};
	if (ctx.req && ctx.req.headers) {
		headers = {
			cookie: ctx.req.headers.cookie,
			origin: ctx.req.headers.host
		};
	}
	// console.log(headers);

	return fetch(api.userInfo, {
		method: 'GET',
		credentials: 'include',
		headers,
	}).then(response => {
		return response.json();
	}).then(res => {
		if (res.code === -4) {
			return {}
		} else {
			return res.data;
		}
	}).catch(err => {
		console.log(err);
	})
}
